package com.swh.controller.business;

import com.github.pagehelper.PageInfo;
import com.swh.entity.QualificationCondition;
import com.swh.entity.Statute;
import com.swh.service.StatuteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

/**
 * @Author: swh
 * @Description:
 * @Date: 2020/12/14 14:41
 * @Version: 1.0
 */
@Controller
@RequestMapping("/gugaunjia/statute")
public class StatuteController {

    @Autowired
    private StatuteService statuteService;

    @RequestMapping("/index")
    public String login() {
        return "statute/index";
    }

    @ResponseBody
    @RequestMapping("/findAll/{pageNum}/{pageSize}")
    public PageInfo<Map> findAll(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize,
                                 QualificationCondition condition) {
        return statuteService.selectPage(pageNum, pageSize,condition);
    }

    //删除//修改
    @ResponseBody
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public void updateById(@RequestBody Statute statute) {
        statuteService.update(statute);
    }


    @RequestMapping("/toUpdate")
    public String tuUpdate() {
        return "/statute/update";
    }

    //根据id查询并且回写数据
    @ResponseBody
    @RequestMapping("/get")
    public Object get(Integer id){
        return statuteService.findById(id);
    }


    //添加
    @ResponseBody
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public void insert(@RequestBody Statute statute) {
        statute.setCreateDate(new Date());
        statute.setUpdateDate(new Date());
        statute.setDelFlag("0");
        statuteService.insert(statute);
    }



}
